﻿
    $(document).ready(function () {
        var win = window;

        function copySubmenu() {
            try {
                if (!win.parent.frames['left']) return;
                var leftWinDoc = $(win.parent.frames['left'].document);
            } catch (e) {
                console.log(e);
                return;
            }
            leftWinDoc.find('#menu .submenu').each((i, v) => {
                var el = $(v).clone(true);
                el.addClass($(v).prev().find('span')[0].className);
                win.document.body.append(el[0]);
            });

            try {
                if (!win.parent.frames['left']) return;
                var leftWinDoc = $(win.parent.frames['left'].document);
            } catch (e) {
                console.log(e);
                return;
            }
            leftWinDoc.find('#menu .submenu').each((i, v) => {
                var el = $(v).clone(true);
                el.addClass($(v).prev().find('span')[0].className);
                win.document.body.append(el[0]);
            });

            var a = '待办事项';
            var b = '隐藏菜单';
            var c = '修改密码';
            var d = '退出系统';
            var e = 'OA登录' ;

            var html = '<div class="submenu setting" style="display: none;">' +
                '<a target="rightfrm" href="/start">' +
                '<span>' + a +'</span>' +
                '</a>' +
                '<a id="hideMenu">' +
                '<span id="hideMenuSpan">' + b +'</span>' +
                '</a>' +
                '<a target="rightfrm" href="/SysAdmin/changepwd">' +
                '<span>' + c +'</span>' +
                '</a>' +
                '<a href="javascript:void(0);" onclick="logout()">' +
                '<span>' + d +'</span>' +
                '</a>' +
                '<a href="javascript:void(0);" onclick="jump2oa()">' + e + '</a>' +
                '</a>' +
                '</div>';
            $(win.document.body).append(html);

            $('.submenu').hover(function(){
                $(this).toggleClass('hovering').show()
            },function(){
                $(this).toggleClass('hovering').hide()
            });

            $('#hideMenu').click(() => {
                let el = window.parent.frames['rightfrm'].document.getElementById('hideMenuSpan')
                let text = el.textContent
                let cont = window.parent.document.getElementById('bottomframes')
                if(text === '隐藏菜单') {
                    cont.cols = "0,*"
                    el.textContent = '显示菜单'
                } else  {
                    cont.cols = "170,*"
                    el.textContent = '隐藏菜单'
                }
            });

        }

        setTimeout(() => {
            copySubmenu()
        }, 300)
    });

    function jump2oa() {
        $.ajax({
            type: 'post',
            // dataType: "json",
            url: "/SysAdmin/jump2oa",
            success: function (msg) {
                window.open(url=msg);
            },
        });
    }

    function logout() {
        $.ajax({
            type: 'post',
            url: "/loginout",
            success: ()=>{
                window.location.reload()
            }
        });
    }